#ifndef LC_A6_MOTOR_H
#define LC_A6_MOTOR_H

#include <QWidget>
#include "canopen.h"

enum{

    CONTORL_STATUS_ADDR = 0x6040,
    PUU_ADDR =0x6064,
    CONTORL_MODE_ADDR = 0x6060,
    TAR_POS_ADDR = 0x607A,
    POR_SPEED_ADDR = 0x6081,
    POR_ACC_ADDR = 0x6083,
    PRO_DEC_ADDR = 0x6084
};

#define roll_scale 142722.84
#define x_scale 524288.0
#define Y_scale 291271.0
namespace Ui {
class LC_A6_Motor;
}

class LC_A6_Motor : public QWidget
{
    Q_OBJECT

public:
    explicit LC_A6_Motor(uint8_t id, int32_t max =0, int32_t min = 0, QWidget *parent = nullptr);
    ~LC_A6_Motor();


    void setName(QString name);
    QString getName(){return m_name;}
    uint8_t getId(){return m_id;}
    uint8_t m_id;
    QString m_name;

    void emitAskPos();
    void enabelMotor();
    void setTarget(int32_t pod);
    void setTarget_2(int32_t pod);
    void setSpeed(uint32_t speed){m_speed = speed;}
    uint32_t m_speed = 200;
    uint32_t m_acc_speed = 100;
    uint32_t m_dec_speed = 100;
    int32_t curPos = 0;
    int32_t targetPos =0;

    int32_t max_pos;
    int32_t min_pos;
    int32_t zeroOffect;
    int32_t mes_id =0;
    void reciveMessage(struct can_frame fam);
    void baseCurPoseAdd(float pos);
    void baseCurPoseDown(float pos);
    void setYawAngle(float angle);
    void setY_Trans(float len);
    void setX_Trans(float len);
    void updateMesId(uint32_t dd);
    void updateTarPos(int32_t pos);
    void setZeroPos(int32_t pos);
    float m_xy =0;
    void upDateYX();
    float getXY(){return m_xy;}

    float m_yaw;
    void upDateYaw();
    float getYaw();

    float m_roll;
    void upDateRoll();
    float getRoll(){return m_roll;}
    bool isArrive();
    void stop();
private slots:
    void on_btnAskPos_clicked();

    void on_btnEnable_clicked();

    void on_btnSetPos_clicked();

    void on_btn_zero_clicked();

    void on_btn_stop_clicked();

private:
    Ui::LC_A6_Motor *ui;
signals:
    void sendMessage(struct can_frame fanm);
};

#endif // LC_A6_MOTOR_H
